package com.test05_数组应用;

/**
 * 引用传递设计案例
 */
public class YootkDemo_01 {

    public static void main(String[] args) {
        // 声明并实例化各自的类对象
        Person per = new Person("张特勒", 40);
        Person child = new Person("李米勒", 25);
        Car car = new Car("奔驰G50", 1588888.00);
        Car sport = new Car("奔驰GLK", 700000.00);
        // 要设置彼此之间的引用关联
        per.setCar(car);
        car.setPerson(per);
        per.setChild(child);
        child.setCar(sport);
        // 依据引用结构获取相关的数据信息
        System.out.println(per.getChild().getInfo());
        System.out.println(per.getChild().getCar().getInfo());
    }
}

/**
 * 描述人
 */
class Person {
    private String name;
    private int age;
    private Car car;        // 车子
    private Person child;   // 孩子

    public Person() {
    }

    public Person(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public void setChild(Person child) {
        this.child = child;
    }

    public Person getChild() {
        return this.child;
    }

    public void setCar(Car car) {
        this.car = car;
    }

    public Car getCar() {
        return this.car;
    }

    public String getInfo() {
        return "【人】姓名：" + this.name + "、年龄：" + this.age;
    }
}

/**
 * 描述车
 */
class Car {
    private String name;
    private double price;
    private Person person;  // 车主

    public Car() {
    }

    public Car(String name, double price) {
        this.name = name;
        this.price = price;
    }

    public void setPerson(Person person) {
        this.person = person;
    }

    public Person getPerson() {
        return this.person;
    }

    public String getInfo() {
        return "【车】品牌：" + this.name + "、价格：" + this.price;
    }
}
